package org.budo.mongo.jdbc.driver.statement.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;

import org.budo.jdbc.driver.AbstractBudoJdbcPreparedStatement;
import org.budo.mongo.jdbc.driver.executor.MongoStatementExecutor;
import org.budo.mongo.jdbc.driver.statement.AbstractMongoStatement;
import org.budo.mongo.jdbc.driver.statement.StatementDocument;

/**
 * @author li
 */
public class MongoUpdateStatement extends AbstractMongoStatement {
    public void execute(PreparedStatement preparedStatement) throws SQLException {
        StatementDocument statementDocument = this.statementDocument(preparedStatement);

        Map<String, Object> where = statementDocument.getWhere();
        Map<String, Object> updateValues = statementDocument.getUpdateValues();

        MongoStatementExecutor statementExecutor = this.statementExecutor(preparedStatement);

        Integer updateCount = statementExecutor.update(this.getCollectionName(), where, updateValues);

        ((AbstractBudoJdbcPreparedStatement) preparedStatement).setUpdateCount(updateCount);
    }
}

//db.getCollection('receptionRecordDetailed').find({$and:[{synDate:'2020-06-17'},{isSystemMessage:{$ne:'0'}}]}).sort({chatTime : -1}).limit(100).forEach(function(item){
//    db.getCollection('receptionRecordDetailed').update({"_id" : item._id},{$set:{"isSystemMessage":'0'}})
//})